package felix.rule.module.transaction;

import felix.rule.api.*;
import felix.rule.api.util.TNodeUtils;
import felix.rule.data.msg.EngineMsg;
import felix.rule.data.plugin.ComponentType;
import lombok.extern.slf4j.Slf4j;


@Slf4j
@RuleNode(
        type = ComponentType.ACTION,
        name = "synchronization end",
        configClazz = EmptyNodeConfiguration.class,
        nodeDescription = "Stops synchronization of message processing based on message originator",
        nodeDetails = "",
        uiResources = {"static/rulenode/rulenode-core-config.js"},
        configDirective = ("tNodeEmptyConfig")
)
public class SynchronizationEndNode implements TNode {

    private EmptyNodeConfiguration config;

    @Override
    public void init(TContext ctx, TNodeConfiguration configuration) throws TNodeException {
        this.config = TNodeUtils.convert(configuration, EmptyNodeConfiguration.class);
    }

    @Override
    public void onMsg(TContext ctx, EngineMsg msg) {
        ctx.getRuleChainTransactionService().endTransaction(msg, ctx::tellSuccess,
                throwable -> ctx.tellFailure(msg, throwable));
        log.trace("Msg left transaction - [{}][{}]", msg.getId(), msg.getType());
    }

    @Override
    public void destroy() {

    }
}
